package com.ssy.controller;

import com.ssy.entity.Result;
import com.ssy.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;

    /**
     * 文件上传阿里云oss存储
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    public Result upload( MultipartFile file) throws Exception {
        log.info("上传文件 {}", file);
        // 1. 将文件交给oss
        String upload = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
        log.info("文件上传 {}", upload);
        return Result.success(upload);
    }
}
